// run: $exec < input
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
#include <utility>

long long const maxn = 105007;
bool vis[maxn];
long long da[maxn];
long long left[maxn];
long long right[maxn];
long long q[maxn];
int n, tail, head;
long long sum, avg;

void push(long long x)
{
	q[tail++] = x;
}

bool empty()
{
	return (head == tail);
}

long long front()
{
	return q[head];
}

void pop()
{
	head++;
}

int main()
{
	int T; std::scanf("%d", &T);
	while (T--) {
		std::scanf("%d", &n);
		sum = 0;
		for (long long i = 0; i < n; i++) { std::scanf("%I64d", &da[i]); sum += da[i]; }
		avg = sum / n;
		if (avg * (long long)(n) != sum) { std::printf("NO\n"); continue; }

		if (n == 2 && std::abs(da[0] - da[1]) > 2) { std::printf("NO\n"); continue; }

		head = tail = 0;

		bool no_solution = false;
		for (int i = 0; i < n; i++) {
			long long tmp = std::abs((long long)da[i] - avg);
			if (tmp > 2) {
				no_solution = true;
				break;
			}
			if (tmp == 2) push(i);
		}

		if (no_solution) { std::printf("NO\n"); continue; }

		std::vector<std::pair<int, int> > ans;
		std::memset(vis, 0, sizeof(vis));

		left[0] = 0;
		for (int i = 1; i < n; i++)
			if (da[i] == avg) left[i] = left[i-1];
			else              left[i] = i;
		right[n-1] = n-1;
		for (int i = n-1; i >= 0; i--)
			if (da[i] == avg) right[i] = right[i+1];
			else              right[i] = i;

		if (da[0] == avg) left[0] = left[n-1];
		if (da[n-1] == avg) right[n-1] = right[0];
		if (empty()) {
			for (int i = 0; i < n; i++) {
				if (da[i] == avg) continue;
				if (left[(i + n - 1) % n] == right[(n + 1) % n]) continue;
				if (da[left[(i + n - 1) % n]] != da[right[(n + 1) % n]]) {
					push(i); break;
				}
			}
		}

		if (empty()) {
			for (long long i = 0; i < n; i++) {
				long long tmp = std::abs((long long)da[i] - avg);
				if (tmp == 0) continue;
				if (da[(i + n - 1) % n] != da[(i + 1) % n]) {
					push(i); break;
				}
			}
		}
		if (empty())
			for (long long i = 0; i < n; i++) {
				long long tmp = std::abs((long long)da[i] - avg);
				if (tmp == 1) {
					push(i);
					break;
				}
			}

		while (!empty()) {
			long long now = front(); pop();
			for (int i = 0; i < n; i++) std::printf("%lld ", da[i]);
			std::printf("\n");
			vis[now] = true;
			long long del = std::abs((long long)da[now] - avg);
			if (del == 2) {
				if (da[now] > avg) {
					da[(now + 1) % n]++;
					da[(now + n - 1) % n]++;
					ans.push_back(std::make_pair(now, (now + 1) % n));
					ans.push_back(std::make_pair(now, (now + n - 1) % n));
					da[now] -= 2;
					if (vis[(now + 1) % n] || vis[(now + n - 1) % n]) {
						no_solution = true;
						break;
					}
					push((now + 1) % n);
					push((now + n - 1) % n);
				} else {
					if (da[(now + 1) % n] < 1 || da[(now + n - 1) % n] < 1) {
						no_solution = true;
						break;
					}
					da[(now + 1) % n]--;
					da[(now + n - 1) % n]--;
					da[now] += 2;
					ans.push_back(std::make_pair((now + 1) % n, now));
					ans.push_back(std::make_pair((now + n - 1) % n, now));
					if (vis[(now + 1) % n] || vis[(now + n - 1) % n]) {
						no_solution = true;
						break;
					}
					push((now + 1) % n);
					push((now + n - 1) % n);
				}
			}

			if (del == 1) {
				if (da[now] > avg) {
					if (vis[(now + n - 1) % n] && vis[(now + 1) % n]) {
						no_solution = true;
						break;
					} else
					if (vis[(now + n - 1) % n]) {
						da[now]--;
						da[(now + 1) % n]++;
						ans.push_back(std::make_pair(now, (now + 1) % n));
						push((now + 1) % n);
					} else
					if (vis[(now + 1) % n]) {
						da[now]--;
						da[(now + n - 1) % n]++;
						ans.push_back(std::make_pair(now, (now + n - 1) % n));
						push((now + n - 1) % n);
					} else {
						da[now]--;
						if (da[(now + 1) % n] < da[(now + n - 1) % n]) {
							da[(now + 1) % n]++;
							ans.push_back(std::make_pair(now, (now + 1) % n));
						} else {
							da[(now + n - 1) % n]++;
							ans.push_back(std::make_pair(now, (now + n - 1) % n));
						}
						push((now + n - 1) % n);
						push((now + 1) % n);
					}
				} else {
					if (vis[(now + n - 1) % n] && vis[(now + 1) % n]) {
						no_solution = true;
						break;
					} else
					if (vis[(now + n - 1) % n]) {
						da[now]++;
						if (da[(now + 1) % n] < 1) {
							no_solution = true;
							break;
						}
						da[(now + 1) % n]--;
						ans.push_back(std::make_pair((now + 1) % n, now));
						push((now + 1) % n);
					} else
					if (vis[(now + 1) % n]) {
						da[now]++;
						if (da[(now + n - 1) % n] < 1) {
							no_solution = true;
							break;
						}
						da[(now + n - 1) % n]--;
						ans.push_back(std::make_pair((now + n - 1) % n, now));
						push((now + n - 1) % n);
					} else {
						da[now]++;
						if (da[(now + 1) % n] > da[(now + n - 1) % n]) {
							if (da[(now + 1) % n] < 1) {
								no_solution = true;
								break;
							}
							da[(now + 1) % n]--;
							ans.push_back(std::make_pair((now + 1) % n, now));
						} else {
							if (da[(now + n - 1) % n] < 1) {
								no_solution = true;
								break;
							}
							da[(now + n - 1) % n]--;
							ans.push_back(std::make_pair((now + n - 1) % n, now));
						}
						push((now + n - 1) % n);
						push((now + 1) % n);
					}
				}
			}

			if (!del) {
				if (!vis[(now + n - 1) % n])
					push((now + n - 1) % n);
				if (!vis[(now + 1) % n])
					push((now + 1) % n);
			}
		}

		if (no_solution) { std::printf("NO\n"); continue; }
		std::printf("YES\n");
		std::printf("%d\n", (int)ans.size());
		for (long long i = 0; i < (long long)ans.size(); i++)
			std::printf("%d %d\n", ans[i].first + 1, ans[i].second + 1);
	}

}
